package com.xidian.zhiancloud.util.zyf;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: Summerless
 * @Date: 2021/4/30 10:28
 */
@Component
public class TicketIdUtil {

    private AtomicInteger i = new AtomicInteger();

    public int addAndGet() {
        return i.incrementAndGet();
    }

    public int getI() {
        return i.intValue();
    }

    public void set(int value) {
        i.set(value);
    }

    /**
     * 每天凌晨重制id
     */
    @Scheduled(cron = "0 0 0 ? * *")
    public void scheduledTask() {
        System.out.println("id重制任务执行时间：" + LocalDateTime.now());
        set(0);
    }
}
